let leftHeight = 0;
let rightHeight = 0;
let leftData = []; //瀑布流生成前临时存放的数组
let rightData = [];
Component({
  options: {
    addGlobalClass: true
  },
  properties: {
    data: {
      type: Array,
      value: [],
      observer: function (newVal, oldVal) {
        this.create()
      }
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    leftData: [],
    rightData: []
  },

  lifetimes: {
    attached() {

    }
  },
  methods: {
    create() {
      let data = this.data.data;
      let promiseArr = [];
      for (let i in data) {
        let p = new Promise((resolve, reject) => {
          wx.getImageInfo({
            src: data[i].image,
            complete: (res) => {
              console.log(res);
              if (leftHeight <= rightHeight) {
                leftHeight += res.height;
                leftData.push(data[i])
              } else {
                rightHeight += res.height;
                rightData.push(data[i])
              }
              resolve()
            }
          })
        })
        promiseArr.push(p)
      }
      Promise.all(promiseArr).then(res => {
        console.log(leftHeight,leftData,rightHeight,rightData)
        console.log(res);
        this.setData({
          leftData,rightData
        })
      })
    }
  }
})